#include "widget.h"
#include "ui_widget.h"
#include<QPushButton>
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);b.setText("重新开始");
    connect(&b,&QPushButton::released,this,&Widget::rechange);
    b.move(2*64,9*64);
    setWindowTitle("推箱子");
    pBox=new boxGame;
    pMap=new QPainter(this); b.setParent(this);
    setFixedSize(10*64,10*64);

  c.setParent(this);c.setText("结束");
  connect(&c,&QPushButton::released,this,&Widget::close);
  c.move(6*64,9*64);
}

Widget::~Widget()
{
    delete ui;
}
void Widget::keyPressEvent(QKeyEvent *event)
{
pBox->Keydown(event);
if(pBox->gameover()){
    this->close();
}
}

void Widget::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
    pMap->begin(this);
    pBox->boxGame::drawmap(pMap);
    pMap->end();
    update();
}

void Widget::rechange()
{
    pBox=new boxGame;
    pMap=new QPainter(this);
}


